/* Copyright (c) 2004-2022 peigen.info. All rights reserved. */

package com.gitee.peigenlpy.actable.config;

import com.zaxxer.hikari.HikariDataSource;
import org.noear.solon.annotation.Bean;
import org.noear.solon.annotation.Configuration;
import org.noear.solon.annotation.Import;
import org.noear.solon.annotation.Inject;

import javax.sql.DataSource;
import java.util.Properties;

/**
 * <b>(ACTableAutoConfiguration)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2023/7/2
 */
@Configuration
@Import(scanPackages = {"com.gitee.peigenlpy.actable", "org.apache.ibatis"})
public class ACTableAutoConfiguration {

    @Inject
    private ActableProperties actableProperties;

    @Bean(name = "dataSource", typed = true)
    public DataSource dataSource(@Inject("${actable.dataSource}") HikariDataSource ds) {
        return ds;
    }

    @Bean
    public void configurationUtilInterceptor() {
        Properties properties = System.getProperties();
        properties.setProperty("actable.database.type", actableProperties.getDatabaseType());
        properties.setProperty("actable.index.prefix", actableProperties.getDatabaseType());
        properties.setProperty("actable.unique.prefix", actableProperties.getDatabaseType());
        properties.setProperty("actable.table.auto", actableProperties.getTableAuto());
        System.setProperties(properties);
    }
}